package raone;

import java.net.*;
import java.io.*;
import java.util.*;

public class Client2 {
	
	public static void main(String[] args)throws Exception{
		int i=0;
		//System.out.println("Client Starting......");
		InetAddress add=InetAddress.getByName("127.0.0.1");
		Socket ClientSocket=new Socket(add,7780);
		BufferedReader in = new BufferedReader(new InputStreamReader(ClientSocket.getInputStream()));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(ClientSocket.getOutputStream()));
        //System.out.println("Enter Value to send :");
		Scanner input=new Scanner(System.in);
		
		String string1;
		String string2;
		try{
			while(i<5){
		
				string1="1";
				Thread.sleep(4000);
				//string1="sfsdf";
				out.println(string1);
				out.flush();
				System.out.println("Client 2 sends : "+string1);
				//string2=in.readLine();
				//System.out.println("client recieves : "+string2);
				i=i+1;
				System.out.println("Print i" +i );
				if(string1.compareToIgnoreCase("end")==0)
					break;
				
				
			}
		}
		finally{
			out.println("0");
			out.flush();
			System.out.println("Ending the Client 2");
			in.close();
			out.close();
			ClientSocket.close();
		}
	}
	
	
	
	
	
}
